package com.ihg.hiex.admin.entity.search;

import java.util.Map;

import com.demo2do.core.persistence.support.QueryBuilder;
import com.demo2do.core.persistence.support.QueryFilter;
import com.demo2do.core.persistence.support.QueryOrder;
import com.ihg.hiex.entity.session.Status;

/**
 * @author Guangli Yan
 *
 */
public class SessionSearch implements QueryBuilder{
	
	/**
	 * Session status.
	 */
	private Status sessionStatus;
	
	private QueryFilter queryFilter;
	
	private QueryOrder queryOrder;
	
	/**
	 * the default constructor.
	 */
	public SessionSearch() {
		
		queryFilter = new QueryFilter();
		
		queryOrder = new QueryOrder();
	}
	
	/* (non-Javadoc)
	 * @see com.demo2do.core.persistence.support.QueryBuilder#getPreparedFilter(boolean)
	 */
	public QueryFilter getPreparedFilter(boolean refresh) {

		if (refresh) {
			queryFilter = new QueryFilter();
		}
		queryFilter.addEquals("status", sessionStatus);
		
		queryFilter.addEquals("disabled", false);
		
		return queryFilter;
	}

	/* (non-Javadoc)
	 * @see com.demo2do.core.persistence.support.QueryBuilder#getOrder()
	 */
	public QueryOrder getOrder() {

		return queryOrder;
	}

	/* (non-Javadoc)
	 * @see com.demo2do.core.persistence.support.QueryBuilder#buildSentenceTemplate()
	 */
	public String buildSentenceTemplate() {

		String sentence = "FROM Session WHERE disabled = false " + getPreparedFilter(false).clauseSentence() + getOrder().sentence();
		
		return sentence;
	}

	/* (non-Javadoc)
	 * @see com.demo2do.core.persistence.support.QueryBuilder#buildParameters()
	 */
	public Map<String, Object> buildParameters() {
		return getPreparedFilter(false).parameters();
	}

	/**
	 * @return the status
	 */
	public Status getStatus() {
		return sessionStatus;
	}

	/**
	 * @param sessionStatus the status to set
	 */
	public void setStatus(Status sessionStatus) {
		this.sessionStatus = sessionStatus;
	}

}
